package com.djz.tool.exception.category;

import com.djz.tool.exception.base.BaseException;
import com.djz.tool.exception.errorcode.BusinessErrorCode;
import lombok.Getter;
import lombok.Setter;

/**
 * 交易异常
 * @author djz
 */
public class BusinessException extends BaseException {

    public static BusinessException BUSINESS_EXCEPTION = new BusinessException(BusinessErrorCode.SYS_OPR_ERR);


    @Getter
    @Setter
    private BusinessErrorCode businessErrorCode;

    @Getter
    @Setter
    private String respSubCode;

    @Getter
    @Setter
    private Object obj;

    public BusinessException(BusinessErrorCode businessErrorCode) {
        super(String.valueOf(businessErrorCode.getCode()), businessErrorCode.getDesc());
    }

    public BusinessException(Integer businessErrorCode, String msg) {
        super(String.valueOf(businessErrorCode), msg);
    }

    public BusinessException(BusinessErrorCode businessErrorCode, String msg, String respSubCode) {
        super(String.valueOf(businessErrorCode.getCode()), msg);
        this.setRespSubCode(respSubCode);
    }

    public BusinessException() {
        super();
    }

    public BusinessException(String code, String msg) {
        super(code, msg);
    }

    public BusinessException(String code, String msg, Object obj) {
        super(code, msg);
        this.obj = obj;
    }

    public BusinessException(String code, String msg, String respSubCode) {
        super(String.valueOf(code), msg);
        this.setRespSubCode(respSubCode);
    }

    @Override
    public String toString() {
        return String.format("TradeException{businessErrorCode=[code=%s,desc=%s]}", getCode(), getMessage());
    }
}
